//
//  ZGWAddCustomBiaoQianViewController.m
//  MyYiJianKangApp
//
//  Created by 张国文 on 16/6/2.
//  Copyright © 2016年 hangzhouyijiyin. All rights reserved.
//

#import "ZGWAddCustomBiaoQianViewController.h"

@interface ZGWAddCustomBiaoQianViewController ()<UITextFieldDelegate>

@property (nonatomic, strong) UITextField *biaoQianTF; // 标签TF

@end

@implementation ZGWAddCustomBiaoQianViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    // navi的修改
    [self changeNavigation];
    // 布局
    [self addMySubview];
}

// navi的修改
- (void)changeNavigation
{
    [self.navigationController.navigationBar setTranslucent:NO];
    self.navigationItem.title = @"添加自定义标签";
    UIImageView *leftImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    leftImageView.image = [UIImage imageNamed:@"houtui"];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftImageView];
    UITapGestureRecognizer *leftTapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(lastPage:)];
    [leftImageView addGestureRecognizer:leftTapGes];
    
    
    
}

#pragma mark - 返回上一页面
- (void)lastPage:(UITapGestureRecognizer *)tapGes
{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - 布局
- (void)addMySubview
{
    self.biaoQianTF = [[UITextField alloc] initWithFrame:CGRectMake(10 * kAdjustParamater, 20 * kAdjustParamater, 355 * kAdjustParamater, 40 * kAdjustParamater)];
    self.biaoQianTF.placeholder = @"请填写标签";
    self.biaoQianTF.font = [UIFont systemFontOfSize:k15Big];
    self.biaoQianTF.tintColor = kCyanColor;
    self.biaoQianTF.textColor = kCyanColor;
    self.biaoQianTF.backgroundColor = [UIColor whiteColor];
    self.biaoQianTF.layer.borderColor = [kCyanColor CGColor];
    self.biaoQianTF.layer.borderWidth = 2 * kAdjustParamater;
    self.biaoQianTF.layer.cornerRadius = 5 * kAdjustParamater;
    self.biaoQianTF.textAlignment = NSTextAlignmentCenter;
    self.biaoQianTF.delegate = self;
    [self.view addSubview:_biaoQianTF];
    
    // 提示框
    UILabel *alertLabel = [[UILabel alloc] initWithFrame:CGRectMake(10 * kAdjustParamater, self.biaoQianTF.bottom + 7 * kAdjustParamater, self.biaoQianTF.width, 15 * kAdjustParamater)];
    alertLabel.text = @"标签的长度为5个字以内,不可以包含空格";
    alertLabel.textColor = [UIColor grayColor];
    alertLabel.font = [UIFont systemFontOfSize:k14Big];
    alertLabel.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:alertLabel];
    
    // 完成
    UIButton *finishButton = [UIButton buttonWithType:UIButtonTypeSystem];
    finishButton.frame = CGRectMake((375 - 150) / 2 * kAdjustParamater, alertLabel.bottom + 17 * kAdjustParamater, 150 * kAdjustParamater, 35 * kAdjustParamater);
    [finishButton setTitle:@"完成" forState:UIControlStateNormal];
    [finishButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    finishButton.titleLabel.font = [UIFont systemFontOfSize:k20Big];
    finishButton.backgroundColor = kCyanColor;
    finishButton.layer.cornerRadius = 5 * kAdjustParamater;
    finishButton.layer.masksToBounds = YES;
    [finishButton addTarget:self action:@selector(finishCustom:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:finishButton];
}

#pragma mark - 完成自定义
- (void)finishCustom:(UIButton *)button
{
    // 判断是否包含空格
    if ([self.biaoQianTF.text containsString:@" "] || self.biaoQianTF.text.length > 5) {
        [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addAlertTitle:@"提醒" Content:@"标签不能包含空格符,并且不能超过5个字符" ToView:self];
    } else {
        NSLog(@"可以添加");
        self.addCustomBiaoQian(self.biaoQianTF.text);
    }
    [self.navigationController popViewControllerAnimated:YES];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}






- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
